function rp_rt()
    t1 = 0; t2 = 0; g = 0; f = 90;
    S0 = 1; S1 = 0; S2 = 0; S3 = 0;
    incident_beam = [S0; S1; S2; S3];
    
    fig = uifigure('Name', 'Matrix Simulation');
    fig.Position = [100 100 500 350]; 
    
    uilabel(fig, 'Text', 't1', 'Position', [100 320 50 22]);
    t1Slider = uislider(fig, 'Limits', [0 360], 'Value', t1, 'Position', [150 320 200 3]);
    t1Edit = uieditfield(fig, 'numeric', 'Value', t1, 'Position', [360 320 100 22]);
    addlistener(t1Slider, 'ValueChanged', @(src, event) updateParameters());
    addlistener(t1Edit, 'ValueChanged', @(src, event) updateParameters());

    uilabel(fig, 'Text', 't2', 'Position', [100 280 50 22]);
    t2Slider = uislider(fig, 'Limits', [0 360], 'Value', t2, 'Position', [150 280 200 3]);
    t2Edit = uieditfield(fig, 'numeric', 'Value', t2, 'Position', [360 280 100 22]);
    addlistener(t2Slider, 'ValueChanged', @(src, event) updateParameters());
    addlistener(t2Edit, 'ValueChanged', @(src, event) updateParameters());
    
    uilabel(fig, 'Text', 'g', 'Position', [100 240 50 22]);
    gSlider = uislider(fig, 'Limits', [0 360], 'Value', g, 'Position', [150 240 200 3]);
    gEdit = uieditfield(fig, 'numeric', 'Value', g, 'Position', [360 240 100 22]);
    addlistener(gSlider, 'ValueChanged', @(src, event) updateParameters());
    addlistener(gEdit, 'ValueChanged', @(src, event) updateParameters());
    
    uilabel(fig, 'Text', 'f', 'Position', [100 200 50 22]);
    fSlider = uislider(fig, 'Limits', [0 360], 'Value', f, 'Position', [150 200 200 3]);
    fEdit = uieditfield(fig, 'numeric', 'Value', f, 'Position', [360 200 100 22]);
    addlistener(fSlider, 'ValueChanged', @(src, event) updateParameters());
    addlistener(fEdit, 'ValueChanged', @(src, event) updateParameters());

    resultArea = uitextarea(fig, 'Position', [50 50 400 130], 'Editable', 'off');
    
    function updateParameters()
        t1 = t1Slider.Value; t1Edit.Value = t1;
        t2 = t2Slider.Value; t2Edit.Value = t2;
        g = gSlider.Value; gEdit.Value = g;
        f = fSlider.Value; fEdit.Value = f;
        
    rotated_polarizer = 0.5 * [1, cosd(2*g)*cosd(2*t1), cosd(2*g)*sind(2*t1), 0;
            cosd(2*g)*cosd(2*t1), cosd(2*t1)^2 + sind(2*g)*sind(2*t1)^2, (1 - sind(2*g))*sind(2*t1)*cosd(2*t1), 0;
            cosd(2*g)*sind(2*t1), (1 - sind(2*g))*sind(2*t1)*cosd(2*t1), sind(2*t1)^2 + sind(2*g)*cosd(2*t1)^2, 0;
            0, 0, 0, sind(2*g)];
    rotated_retarder = [1, 0, 0, 0;
            0, (cosd(2*t2))^2 + cosd(f)*sind(2*t2)^2, (1 - cosd(f))*sind(2*t2)*cosd(2*t2), -sind(f)*sind(2*t2);
            0, (1 - cosd(f))*sind(2*t2)*cosd(2*t2), sind(2*t2)^2 + cosd(f)*cosd(2*t2)^2, sind(f)*cosd(2*t2);
            0, sind(f)*sind(2*t2), -sind(f)*cosd(2*t2), cosd(f)];
        
        emerging_beam = rotated_retarder * rotated_polarizer * incident_beam;
        
        resultStr = sprintf('Emerging Beam:\nS0: %f\nS1: %f\nS2: %f\nS3: %f', emerging_beam);
        resultArea.Value = resultStr;
    end
end


